package org.ehe.erp.domain.finance.vo;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.format.DateTimeFormat;
import cn.idev.excel.converters.Converter;
import cn.idev.excel.metadata.GlobalConfiguration;
import cn.idev.excel.metadata.data.WriteCellData;
import cn.idev.excel.metadata.property.ExcelContentProperty;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import org.ehe.erp.domain.finance.ErpFinancePayment;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * @author :zhangnn
 * @className :ErpFinancePaymentVo
 * @description: TODO
 * @date 2025-08-18 14:22:21
 */

@Data
@ExcelIgnoreUnannotated
@AutoMapper(target = ErpFinancePayment.class)
public class ErpFinancePaymentVo implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 主键ID
     */
    @ExcelProperty(value = "主键ID")
    private Long id;

    /**
     * 付款单号
     */
    @ExcelProperty(value = "付款单号")
    private String no;

    /**
     * 采购单号
     */
    private String purchaseOrderNo;
    /**
     * 采购单名称
     */
    private String purchaseOrderName;

    /**
     * 批次id
     */
    private Long batchId;
    /**
     * 批次名称
     */
    private String batchName;

    /**
     * 状态
     */
    @ExcelProperty(value = "状态", converter = PaymentStatusConverter.class)
    private Integer status;

    /**
     * 状态名称
     */
    private String statusName;

    /**
     * 付款时间
     */
    @ExcelProperty(value = "付款时间")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime paymentTime;

    /**
     * 财务人员编号
     */
    private Long financeUserId;

    /**
     * 财务人员姓名
     */
    @ExcelProperty(value = "财务人员")
    private String financeUserName;

    /**
     * 供应商编号
     */
    private Long supplierId;

    /**
     * 供应商名称
     */
    @ExcelProperty(value = "供应商名称")
    private String supplierName;

    /**
     * 付款账户编号
     */
    private Long accountId;

    /**
     * 账户名称
     */
    @ExcelProperty(value = "付款账户")
    private String accountName;

    /**
     * 合计价格，单位：元
     */
    @ExcelProperty(value = "合计价格")
    private BigDecimal totalPrice;

    /**
     * 优惠金额，单位：元
     */
    @ExcelProperty(value = "优惠金额")
    private BigDecimal discountPrice;

    /**
     * 实付金额，单位：元
     */
    @ExcelProperty(value = "实付金额")
    private BigDecimal paymentPrice;

    /**
     * 备注
     */
    @ExcelProperty(value = "备注")
    private String remark;

    /**
     * 创建人
     */
    @ExcelProperty(value = "创建人")
    private String createByName;

    /**
     * 创建时间
     */
    @ExcelProperty(value = "创建时间")
    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    /**
     * 更新人
     */
    private String updateByName;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    /**
     * 创建部门
     */
    private Long createDept;

    /**
     * 创建部门名称
     */
    @ExcelProperty(value = "创建部门")
    private String createDeptName;

    /**
     * 获取状态名称
     */
    public String getStatusName() {
        if (status == null) {
            return "";
        }
        switch (status) {
            case 0:
                return "草稿";
            case 1:
                return "已审核";
            case 2:
                return "已付款";
            case 9:
                return "已取消";
            default:
                return "未知";
        }
    }

    /**
     * 付款单状态转换器
     */
    public static class PaymentStatusConverter implements Converter<Integer> {
        @Override
        public Class<?> supportJavaTypeKey() {
            return Integer.class;
        }

        @Override
        public WriteCellData<String> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
            if (value == null) {
                return new WriteCellData<>("");
            }
            switch (value) {
                case 0:
                    return new WriteCellData<>("草稿");
                case 1:
                    return new WriteCellData<>("已审核");
                case 2:
                    return new WriteCellData<>("已付款");
                case 9:
                    return new WriteCellData<>("已取消");
                default:
                    return new WriteCellData<>("未知");
            }
        }

//        @Override
//        public Integer convertToJavaData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
//            if (value == null || value.trim().isEmpty()) {
//                return null;
//            }
//            switch (value.trim()) {
//                case "草稿":
//                    return 0;
//                case "已审核":
//                    return 1;
//                case "已付款":
//                    return 2;
//                case "已取消":
//                    return 9;
//                default:
//                    return null;
//            }
//        }
    }
}
